'''
Created on Nov 25, 2010

@author: behrooz
'''

from django.utils.translation import ugettext as _

"""
    page_id -> [title, url]
"""
all_pages = {
    'home': [_("Home"), '/'],
    'login': [_("Login"), '/core/login/'],
    'signup': [_("Sign Up"), '/core/signup/'],
    
    'ad_view': [_("Ad View"), '/ads/view/%s/'],
    'ad_register': [_("Register New Ad"), '/ads/register/'],
    'ad_list': [_("My Ads"), '/my/'],
    'ad_update': [_("Edit"), '/ads/update/%s/'],
    'ad_orders': [_("My Orders"), '/my/orders/'],
    'ad_order_pay': [_("Payment"), '/ads/orders/pay/%s/'],
    'ad_order_payment_list': [_("My Payments"), '/my/payments/'],
    'deposit_list': [_("My Deposits"), '/my/deposits/'],
    'advertizer_list': [_("My Advertizers"), '/my/advertizers/'],
    'advertizer_update': [_("Edit"), '/my/advertizers/update/%s/'],
    'advertizer_new': [_("Register New Advertizer"), '/my/advertizers/register/'],
    'report_list': [_("Reports"), '/my/reports/'],
    
    'ad_explore': [_("Explore Ads"), '/ads/explore/'],
    'ad_explore_mode': [_("Explore Ads"), '/ads/explore/%s/'],
    'ad_explore_by_tag': [_("Explore Ads"), '/ads/tag/explore/%s/'],
    'ad_explore_by_advertizer': [_("Explore Ads"), '/ads/explore/advertizer/%s/'],
    'ad_explore_by_query': [_("Search"), '/ads/search/?query=%s'],
    
    'report_ad_like_dislike': [_("Popularity"), '/report/ads/likes/%s/'],
    'report_ad_view_history': [_("View History"), '/report/ads/views/%s/'],
    
    'faq_list': [_("FAQ"), '/faq/'],
    'faq_submit': [_("Ask Question"), '/faq/submit/'],
 
    'profile_update': [_("Profile"), '/settings/profile/'],
    'notifications': [_("Notifications"), '/settings/notifications/'],
    'password_change': [_("Password change"), '/settings/password_change/'],
    'password_change_done': [_("Password change successful"), '/settings/password_change/done/'],
    'password_reset': [_("Password reset"), '/settings/password_reset/'],
    'password_reset_done': [_("Password reset successful"), '/settings/password_reset/done/'],
    'password_reset_complete': [_("Password reset complete"), '/settings/reset/done/'],
    'deactivate': [_("Deactivate"), '/settings/deactivate/'],
    
    'contact_us': [_("Contact us"), '/about/contact/'],
    'mass_email': [_("Mass e-mail"), '/about/massemail/'],
}

"""
    page_id -> [page_id, [page_id, ...]]
"""
pagecrumbs = {
    'login': ['login'],
    'signup': ['signup'],
              
    'ad_view': ['ad_view'],
    'ad_register': ['ad_register'],
    'ad_register_confirm': ['ad_register'],
    'ad_list': ['ad_list'],
    'ad_update': ['ad_list', 'ad_update'],
    'ad_orders': ['ad_orders'],
    'ad_order_pay': ['ad_orders', 'ad_order_pay'],
    'ad_order_payment_list': ['ad_order_payment_list'],
    'deposit_list': ['deposit_list'],
    'advertizer_list': ['advertizer_list'],
    'advertizer_update': ['advertizer_list', 'advertizer_update'],
    'advertizer_new': ['advertizer_list', 'advertizer_new'],
    'report_list': ['report_list'],
    
    'ad_explore': ['ad_explore'],
    'ad_explore_mode': ['ad_explore_mode'],
    'ad_explore_by_tag': ['ad_explore_by_tag'],
    'ad_explore_by_advertizer': ['ad_explore_by_advertizer'],
    'ad_explore_by_query': ['ad_explore_by_query'],
    
    'report_ad_like_dislike': ['report_list', 'report_ad_like_dislike'],
    'report_ad_view_history': ['report_list', 'report_ad_view_history'],
    
    'faq_list': ['faq_list'],
    'faq_submit': ['faq_list', 'faq_submit'],
    
    'profile_update': ['profile_update'],
    'notifications': ['notifications'],
    'password_change': ['password_change'],
    'password_change_done': ['password_change', 'password_change_done'],
    'password_reset': ['password_change'],
    'password_reset_done': ['password_reset', 'password_reset_done'],
    'password_reset_complete': ['password_reset_complete'],
    'deactivate': ['deactivate'],
    
    'contact_us': ['contact_us'],
    'mass_email': ['mass_email'],
}

def url_refiner(s, param):
    if s.find("%s") > -1:
        return s % param
    return s

def breadcrumb(request, key, param=None, uf=url_refiner):
    if not pagecrumbs.__contains__(key):
        return []
    bcs = [all_pages.get('home')]
    crumbs = pagecrumbs.get(key)
    for p in crumbs:
        bc = all_pages.get(p)
        if param is not None:
            try:
                bcs.append([bc[0], uf(bc[1], param)])
            except:
                bcs.append(bc)
        else:
            bcs.append(bc)
    request.breadcrumbs(bcs)
    return bcs
